package main

import (
	"bufio"
	"fmt"
	"golang.org/x/net/websocket"
	"io"
	"mytest/mj/proto"
	"net/http"
)

func EchoServer(ws *websocket.Conn) {
	reader := bufio.NewReader(ws)
	for {
		cmd, scmd, msg, err := proto.Decode(reader)
		if err == io.EOF {
			return
		}
		if err != nil {
			fmt.Println("decode msg failed, err:", err)
			return
		}
		fmt.Printf("收到client发来的数据： cmd:%v, scmd:%v, msg:%s \n", cmd, scmd, msg)
	}
}

func main() {
	http.Handle("/echo", websocket.Handler(EchoServer))
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		panic("ListenAndServer: " + err.Error())
	}
}
